import yaml
import os
from Basic.global_variables_path import *

def read_yaml(yaml_name):
    yaml_path = os.path.join(global_testcase_path, yaml_name)
    with open(yaml_path, 'r', encoding='utf-8') as f:
        value = f.read()
        yaml_data = yaml.safe_load(value)
        return yaml_data

# 写入数据到yaml文件里面.注意下方的mode,等于a为追加，等于w为清空后重写
def write_yaml(yaml_name, data):
    yaml_path = os.path.join(global_testcase_path, yaml_name)
    with open(yaml_path, encoding="utf-8", mode="a") as f:
        yaml.dump(data, stream=f, allow_unicode=True)

# 清空.mode="w"
def clear_yaml(yaml_name):
    global_yaml_path = os.path.join(global_testcase_path, yaml_name)
    with open(global_yaml_path, encoding="utf-8", mode="w") as f:
        f.truncate()

#读取测试用例
def read_testcase(yaml_name):
    yaml_path = os.path.join(global_testcase_path, yaml_name)
    with open(yaml_path, 'r', encoding='utf-8') as f:
        yaml_data = yaml.safe_load(stream=f)
        # print(value)
        return yaml_data